package queue;

import java.util.Scanner;

public class ArrayQueueDemo {
    public static void main(String[] args) {
        ArrayQuue arrayQuue = new ArrayQuue(3);
        char key=' ';
        Scanner scanner=new Scanner(System.in);
        boolean loop=true;

        while (loop){
            System.out.println("s:显示队列");
            System.out.println("e:退出程序");
            System.out.println("a:添加数据");
            System.out.println("g:读取数据");
            System.out.println("h:显示队列头");
            key=scanner.next().charAt(0); //接受一个字符
            switch (key){
                case 's':
                    arrayQuue.showQueue();
                    break;
                case 'a':
                    int value=scanner.nextInt();
                    arrayQuue.addQueue(value);
                    break;
                case 'g':
                    try {
                        int res=arrayQuue.getQueue();
                        System.out.println("取出数据为" +res);
                    }catch (Exception e) {
                        System.out.println(e.getMessage());
                    }
                    break;
                case 'h':
                    try {
                        int i = arrayQuue.headQueue();
                        System.out.println("队列头的数据是"+i);
                    }catch (Exception e) {
                        System.out.println(e.getMessage());
                    }
                    break;
                case 'e':
                    scanner.close();
                    loop=false;
                    break;
                default:
                    break;
            }
        }
        System.out.println("程序退出！");
    }
}
